/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package net.wofly.sale.commodity.repository;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import net.wofly.sale.commodity.domain.CommodityChannel;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author siqingwei
 */
public interface CommodityChannelRepository
		extends PagingAndSortingRepository<CommodityChannel, String>, JpaSpecificationExecutor<CommodityChannel> {

	List<CommodityChannel> findByCommodityChannelCode(@Param("commodityChannelCode") String commodityChannelCode);

	@Query("from CommodityChannel c where commodityID = :commodityID order by channel asc")
	List<CommodityChannel> findByCommodityID(@Param("commodityID") String commodityID);

	List<CommodityChannel> findByCommodityIDAndChannelAndStatus(String commodityID, String channel, Integer status);
	
	List<CommodityChannel> getAllByStatus(Integer status ,Sort sort);

	/**
	 * 根据商品渠道ID查询商品名称
	 *
	 * @param commodityChannelID
	 * @return
     */
	@Query(value = "select c.commodityName from CommodityChannel cc, Commodity c where cc.commodityID = c.commodityID and " +
			"cc.commodityChannelID = :commodityChannelID")
	String findCommodityNameByCommodityChannelID(@Param("commodityChannelID") String commodityChannelID);
	
	List<CommodityChannel> findByChannelAndStatus(String channel , Integer status);
}